package com.bk.bookviews.service.impl;

import com.bk.bookviews.common.Constants;
import com.bk.bookviews.domain.Picture;
import com.bk.bookviews.domain.PictureExample;
import com.bk.bookviews.mapper.PictureMapper;
import com.bk.bookviews.service.PictureService;
import com.bk.bookviews.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PictureServiceImpl implements PictureService {

    @Autowired
    private PictureMapper pictureMapper;

    @Override
    public List<Picture> selectPictureList(Picture picture) {
        PictureExample pictureExample = new PictureExample();
        PictureExample.Criteria criteria = pictureExample.createCriteria();
        criteria.andPictureStatuEqualTo(Constants.PICTURE_STATUS_NORMAL);

        if (picture != null && picture.getPictureId() != null){
            criteria.andPictureIdEqualTo(picture.getPictureId());
        }
        if (picture != null && picture.getScenicId() != null){
            criteria.andScenicIdEqualTo(picture.getScenicId());
        }
        if (picture != null && StringUtil.isNotBlank(picture.getPictureType())){
            criteria.andPictureTypeEqualTo(picture.getPictureType());
        }
        return pictureMapper.selectByExample(pictureExample);
    }

}
